package org.fusionide.builder.parsers.cfml.tags;

import java.util.Vector;

import org.fusionide.builder.parsers.IParserHandler;
import org.fusionide.builder.parsers.ParserException;
import org.fusionide.builder.parsers.cfml.CFMLTag;
import org.fusionide.builder.parsers.cfml.Variable;

public class Case extends CFMLTag {
	public String value;

	public String delimiter;

	public boolean defaultcase;

	public Case(String attributes, int startOffset) {
		super(attributes, startOffset);

		if (attributes == null)
			return;

		this.value = getAttribute("value");
		this.delimiter = getAttribute("delimiter");
		this.defaultcase = false;
	}

	@Override
	public boolean requiresClosingTag() {
		return true;
	}

	@Override
	public boolean validate(IParserHandler parserHandler) {
		if (super.validate(parserHandler)) {
			if (value == null && !defaultcase) {
				if (parserHandler != null)
					parserHandler.addMarker(new ParserException("<cfcase> Requires value attribute", ParserException.SEVERITY_ERROR, startLine));
				return false;
			}
			return true;
		}
		return false;
	}

	@Override
	public Vector<Variable> getVariables(int offset) {
		return super.getChildVariables(offset);
	}

	public String getDelimiter() {
		return delimiter;
	}

	public void setDelimiter(String delimiter) {
		this.delimiter = delimiter;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public boolean isDefaultcase() {
		return defaultcase;
	}

	public void setDefaultcase(boolean defaultcase) {
		this.defaultcase = defaultcase;
	}
}
